<template>
  <div>
    <list ref="list">
      <template #toolbar-left>
        <el-button @click="syncCheckAmountToEs" type="primary" :loading="syncCurrencyBillEsLoading">同步到ES</el-button>
      </template>
    </list>
  </div>
</template>

<script>
import list from "@/components/fam/check/list";
import api from "@/api/fam/check";

export default {
  components: {
    list
  },
  data() {
    return {
      syncCurrencyBillEsLoading: false
    };
  },
  mounted() {
    this.$refs.list.reload();
  },
  created() { },
  methods: {
    syncCheckAmountToEs() {
      var rows = this.$refs.list.getCheckedRows();
      let message = "确定要将选中的核销单同步到ES吗？";
      let postData;
      if (rows && rows.length > 0) {
        postData = { ids: rows.map((item) => item.id) };
      } else {
        message = "确定要将核销单列表查询结果同步到ES吗？"
        postData = this.$refs.list.$refs.list.tempQueryParams;
      }
      this.$confirm(message, "提示", {
        type: "warning",
      })
        .then(() => {
          this.syncCurrencyBillEsLoading = true;
          api.syncCheckAmountToEs(postData).then((res) => {
            this.syncCurrencyBillEsLoading = false;
          });
        })
        .catch(() => { });
    }
  },
};
</script>